/**
 * ===========================================================================
 * File:   misc.c
 * Author: gustavo
 *
 * Created on October 25, 2010, 3:22 PM
 * ---------------------------------------------------------------------------
 *
 *  Copyright (C) 2010  Gustavo Teodoro Laureano - <gustavoengdm@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * ===========================================================================
 **/

#include <stdlib.h>

int swapEndianInt( int bEnum )
{
    int lEnum;
    char *lE = (char*) &lEnum;
    char *bE = (char*) &bEnum;
    lE[0] = bE[3];
    lE[1] = bE[2];
    lE[2] = bE[1];
    lE[3] = bE[0];
    return lEnum;
}

char * int2bin( int val, int size )
{
    char * str;
    int MASK = 1;
    int idx = 0;

    str = (char *) malloc( sizeof(char) * size );

    for( idx = size-1; idx >= 0; idx--, MASK<<=1 )
        str[idx] = (val&MASK)!=0?'1':'0';

    str[size]='\0';
    return str;
}

int * create_int_sequence(int length, int start, int increment) {
	int i, inc;
	int * shift;
	
	shift = calloc(length, sizeof (int));
	for (i = 0, inc = start; i < length; i++, inc += increment) shift[i] = inc;

	return shift;
}
